package i_Inst;

import mips.Register;
import mips.Decoder;
import mips.PC;


public class Sltui  {
  
  	public static void sltui(int dest , int sc1 , int sc2)
	{
  		String oldvalue = Decoder.toBinary(Register.registers[sc1]);
		if((Decoder.toBinary((Register.registers[sc1]))+"").charAt(0) == '1')
		{
			Register.registers[sc1] = Decoder.toInt("0"+Decoder.toBinary((Register.registers[sc1])));
		}
		
		if (Register.registers[sc1] < sc2)
			Register.registers[dest] = 1;
		else
			Register.registers[dest] = 0;
			
		print(dest, sc1, sc2, oldvalue);
	}

  
  public static void print(int dest,int sc1,int sc2, String oldvalue) {
	  
	  	System.out.println("PC value now is : " +Decoder.toBinary(PC.pc));
	  
		System.out.println("PC value :"+ Decoder.toBinary(PC.pc)+" sent to The instruction memory to read address..");
		
		System.out.println("Instuction memory sending Instruction[25:21] : "+Decoder.AddzerostoLeft(Decoder.toBinary(sc1)+"",5)+" to Registers @ read Register1");
		System.out.println("CONTROL sends RegDst to mux with value 0 ");
		System.out.println("CONTROL sends RegWrite with value 1 ");
		System.out.println("Instuction memory sending Instruction[15:11] : "+Decoder.AddzerostoLeft(Decoder.toBinary(dest)+"",5)+" to Registers @ write Register");
		System.out.println("Register number  read now is : " + Decoder.AddzerostoLeft(Decoder.toBinary(sc1)+"",5));
		System.out.println("Register number  (Destination) is : " + Decoder.AddzerostoLeft(Decoder.toBinary(dest)+"",5));
		
		System.out.println("Instuction memory sending Instruction[15:0] to Sign Extend: " + Decoder.AddzerostoLeft(Decoder.toBinary(sc2)+"",16));
		System.out.println("The constant after Sign Extend: " + Decoder.signExtend(Decoder.AddzerostoLeft(Decoder.toBinary(sc2) + "", 16)+"",32));
		
		System.out.println("CONTROL sends ALUSrc to ALU CONTROL carrying the value 1 to the mux...");
		System.out.println("The mux selects 1 as the second source...");
		
		System.out.println("CONTROL sends ALUOP : 111 to ALU CONTROL");
		
		System.out.println("Register 1 sends first source value : "+ oldvalue + " Second Source value : " + Decoder.toBinary(sc2) + "  to ALU");
		System.out.println("ALU is doing the 'sltu : 1000' operating now...");
		System.out.println("Result is ready :" + Decoder.toBinary(Register.registers[dest]));
		System.out.println("CONTROL send MemtoReg carrying the value 0 to the mux...");
		System.out.println("Sending to the mux...");
		System.out.println("Mux selection is 0,Alu result : "+ Decoder.toBinary(Register.registers[dest]) +" is sent now to the registers @ write data");
		System.out.println("Register : " +  Decoder.AddzerostoLeft(Decoder.toBinary(dest)+"",5) + ",have value now : " +Decoder.toBinary(Register.registers[dest]));
		
		System.out.println("PC value sent to Add");
		PC.pc +=4;
		System.out.println("pc value now is incremented by 4 and passed to the mux :"+Decoder.toBinary(PC.pc)+",selection 0 occured");
		System.out.println("Mux sent back to PC");
		System.out.println("New value of PC now is : " + Decoder.toBinary(PC.pc));
		System.out.println("Executing next Instruction....");
  
  
  }
}
